<?php
	class Form{
		private $formFinal;
		
		function __construct($cible=NULL,$meth=NULL,$id=NULL,$enc=NULL){
			$this->formFinal = "<form ";
			
			if($id)
				$this->formFinal .="id='".$id."' ";                
            if($enc)
				$this->formFinal .="enctype='".$enc."' ";				
			if($cible)
				$this->addAction($cible);
			if($meth)
				$this->addMethod($meth);
		}
		
		public function addAction($cible){
			$this->formFinal .= " action='".$cible."' ";
		}
		
		public function addMethod($meth){
			$this->formFinal .= " method='".$meth."' >";
		}
		
		public function addInput($type, $name,$id=NULL,$label=NULL, $value=NULL, $placehold=NULL){
			if($label && $id)
				$this->formFinal .="<label for='".$id."'>".$label."</label>";
				
			$this->formFinal .= "<input type='".$type."' name='".$name."' ";
			
			if($id)
				$this->formFinal .= "id='".$id."' ";
				
			if($value)
				$this->formFinal .= "value='".$value."' ";

			if($placehold)
				$this->formFinal .= "placeholder='".$placehold."' >";
			else
				$this->formFinal .= " >";
		}
		
		public function addSelection(array $c,$id=NULL,$label=NULL,$select=NULL){
			$i = 0;
			if($id && $label)
				$this->formFinal .= "<label for='".$id."'>".$label."</label>";
				
			if($id)
				$this->formFinal .= "<select id='".$id."'>";
			else
				$this->formFinal .= "<select>";
				
			foreach($c as $k=>$v){
				if($i == $select){
					$this->formFinal .= "<option value='".$k."' selected='selected'>".$v."</option>";
				}else{
					$this->formFinal .= "<option value='".$k."'>".$v."</option>";
				}
				
				$i++;
			}
				
			$this->formFinal .= "</select>";
		}
		
		public function addArea($text = ""){
			$this->formFinal .= "<textarea>".$text."</textarea>";
		}
		
		public function afficheForm(){
			$this->formFinal .= "</form>";
			echo $this->formFinal;
		}
	}
?>